package com.hyz.service.impl;

import client.LogClient;
import com.hyz.pojo.ResponseResult;
import com.hyz.pojo.assetSecondment.AssetSecondmentRequest;
import com.hyz.pojo.assetSecondment.AssetSecondmentResponse;
import com.hyz.service.InformationService;
import com.hyz.util.Conversion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.log.IsComplete;
import pojo.log.assetSecondment.AssetSecondment;
import pojo.log.assetSecondment.AssetSecondmentResultEnum;
import pojo.log.assetSecondment.AssetSecondmentStatusEnum;

import java.util.List;

/**
 * @author HGD
 * @date 2022/10/6 17:09
 */
@Service
public class InformationServiceImpl implements InformationService {
    @Autowired
    private LogClient logClient;
    @Autowired
    private Conversion conversion;

    @Override
    public ResponseResult<List<AssetSecondmentResponse>> ifGetAssetSecondment() {
        AssetSecondment assetSecondment = AssetSecondment.builder().status(AssetSecondmentStatusEnum.TRANSFERS).result(AssetSecondmentResultEnum.CREATE).isComplete(IsComplete.UNFINISHED).build();
        List<AssetSecondment> assetSecondments = logClient.getAssetSecondments(assetSecondment);
        List<AssetSecondmentResponse> responses = conversion.getAssetSecondmentResponse(assetSecondments);
        return new ResponseResult<>(200, "成功", responses);
    }

    @Override
    public ResponseResult<List<AssetSecondmentResponse>> ifUpdateAssetSecondment(AssetSecondmentRequest request) {
        Boolean result = request.getResult();
        Long id = request.getId();
        AssetSecondment assetSecondment = AssetSecondment
                .builder()
                .id(id)
                .result(result
                        ? AssetSecondmentResultEnum.INFORMATION_AGREE
                        : AssetSecondmentResultEnum.FAILED)
                .build();
        logClient.updateAssetSecondmentById(assetSecondment);
        return ifGetAssetSecondment();
    }


}
